<!--读者借阅证信息修改-->

<html>
<head>
    <meta charset="utf-8">
    <!--<meta http-equiv="X-UA-Compatible" content="IE=edge">-->
    <!--<meta name="viewport" content="width=device-width, initial-scale=1">-->
    <title>${readercard.name}的主页</title>
    <!--<link rel="stylesheet" href="css/bootstrap.min.css">-->
    <!--<script src="js/jquery-3.3.1.js"></script>-->
    <!--<script src="js/bootstrap.min.js" ></script>-->

    <style>
        body{
            background-color: rgb(240,242,245);
        }
    </style>
</head>
<body>
<div class="col-xs-5 col-md-offset-3">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">
                信息修改
            </h3>
        </div>
        <div class="panel-body">
            <form method="post" id="edit" >

                <div class="input-group">
                    <span  class="input-group-addon">读者证号</span>
                    <input type="text" readonly="readonly" class="form-control" name="reader_id" id="reader_id" value="">
                </div>
                <div class="input-group">
                    <span class="input-group-addon">姓名</span>
                    <input type="text" class="form-control" name="name" id="name" value="" >
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">性别</span>
                    <input type="text" class="form-control" name="sex" id="sex"  value="" >
                </div>
                <div class="input-group">
                    <span class="input-group-addon">生日</span>
                    <input type="text" class="form-control" name="birth" id="birth"  value="" >
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">地址</span>
                    <input type="text" class="form-control" name="address" id="address"  value="" >
                </div>
                <div class="input-group">
                    <span  class="input-group-addon">电话</span>
                    <input type="text" class="form-control" name="telcode" id="telcode"  value="" >
                </div>
                <br/>
                <input id="msg_btn" type="submit" value="确定" class="btn btn-success btn-sm" class="text-left">
            </form>
        </div>
    </div>
</div>


</body>
<script>
    function mySubmit(flag){
        return flag;
    }
    $("#edit").submit(function () {
        if($("#name").val()==''||$("#sex").val()==''||$("#birth").val()==''||$("#address").val()==''||$("#telcode").val()==''){
            alert("请填入完整图书信息！");
            return mySubmit(false);
        }
    })
</script>
<script>
    $(function () {
        $.ajax({
            type: "post",
            dataType: "json",
            url: "user/selectReader",
            success: function (data) {

                $("#reader_id").val(data.reader_id);
                $("#name").val(data.name);
                $("#sex").val(data.sex);
                $("#birth").val(format(data.birth));
                $("#address").val(data.address);
                $("#telcode").val(data.telcode);


                $("#msg_btn").click(function () {
                    $.ajax({
                        type:"post",
                        dataType:"json",
                        url:"user/readerUpdate",
                        data:$("#edit").serialize(),
                        success:function (data) {
                            alert("修改成功！")
                            // location.href="reader_info.html?reader_id="+data.reader_id;
                            reader_load();
                            $("#middle").load("reader_info.html");
                        }
                    })
                    return false;
                })
            }
        })


    })

    function format(object) {
        var year = new Date(object).getFullYear(); //获取完整的年份(4位,1970-????)
        var month = new Date(object).getMonth() + 1; //获取当前月份(0-11,0代表1月)
        var day = new Date(object).getDate(); //获取当前日(1-31)
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        var dateString =  year + "-" + month + "-" + day;
        return dateString;

    }


</script>
</html>
